import { PageParam } from '@/services/common'
import { covertTableData } from '@/utils/tableUtil'
import { request } from '@umijs/max'

export interface ActivityAwardVO {
  /**
   * 奖品id
   */
  id: string
  /**
   * 奖品名
   */
  awardName: string
  /**
   * 奖品图片
   */
  awardHeadImg: string
  /**
   * 领取规则
   */
  receiveRule: string
  /**
   * 领取限制
   */
  receiveLimit: number
}

export interface ActivityAwardQueryDTO extends PageParam {
  /**
   * 奖品id
   */
  id: string
}
export interface ActivityAwardUpdateDTO {
  /**
   * 奖品id
   */
  id?: string
  /**
   * 奖品名
   */
  awardName?: string
  /**
   * 奖品图片
   */
  awardHeadImg?: string
  /**
   * 领取规则
   */
  receiveRule?: string
  /**
   * 领取限制
   */
  receiveLimit?: number
}

export const getActivityAwardById = async (id: string) => {
  return request<ActivityAwardVO>(`/api/activityAward?id=${id}`, { method: 'GET' })
}

export const getActivityAwardList = async (params: ActivityAwardQueryDTO) => {
  return request<Array<ActivityAwardVO>>(`/api/activityAward/list`, { method: 'GET', params })
}

export const getActivityAwardPage = async (params: ActivityAwardQueryDTO) => {
  let response = await request<Array<ActivityAwardVO>>(`/api/activityAward/page`, { method: 'GET', params })
  return covertTableData(response)
}

export const updateActivityAward = async (activityAwardUpdateDTO: ActivityAwardUpdateDTO) => {
  return request<ActivityAwardVO>(`/api/activityAward/update`, { method: 'POST', data: activityAwardUpdateDTO })
}

export const saveActivityAward = async (activityAwardUpdateDTO: ActivityAwardUpdateDTO) => {
  return request<ActivityAwardVO>(`/api/activityAward/save`, { method: 'POST', data: activityAwardUpdateDTO })
}

export const removeActivityAward = async (id: string) => {
  return request<boolean>(`/api/activityAward/remove?id=${id}`, { method: 'POST' })
}
